<template>
  <div class="app-container">
    <div class="container" style="padding-bottom: 50px">
      <!--标签栏-->
      <el-tabs v-model="activeName">
        <!--        <el-tab-pane label="店铺信息" name="1" />-->
        <!--        <el-tab-pane label="地址管理" name="2" />-->
        <!--        <el-tab-pane label="运费模板" name="3" />-->
        <el-tab-pane label="通用设置" name="4" />
        <!--        <el-tab-pane label="交易设置" name="5" />-->
        <el-tab-pane label="分佣设置" name="6" />
      </el-tabs>
      <!--工具栏-->
      <div style="margin-top: 15px">
        <!--店铺信息-->
        <el-form v-loading="loading" v-show="statusId === 1" :rules="rules" :model="shop" label-width="120px" >
          <el-form-item label="店铺名称:" prop="shop_name">
            <el-input v-model="shop.mall_name" style="width: 400px;" />
          </el-form-item>
          <el-form-item label="联系电话:">
            <el-input v-model="shop.mobile" style="width: 400px;" />
          </el-form-item>
          <el-form-item v-if="false" label="管理员" />
          <el-form-item label="经纬度:">
            <el-input v-model="shop.location" style="width: 400px;" />
          </el-form-item>
          <el-form-item label="商铺地址:">
            <el-input v-model="shop.address" style="width: 400px;" />
          </el-form-item>
          <el-form-item label="店铺logo:">
            <el-upload
              :show-file-list="false"
              :on-success="logoImgSuccess"
              :before-upload="beforeUserImgUpload"
              :action="userHeadUploadApi"
              class="avatar-uploader">
              <img v-if="shop.icon" :src="shop.icon" style="width: 100px; height: 100px" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon" />
            </el-upload>
            <div style="font-size: 10px;color:#606266">建议尺寸：200×200px ，大小不能超过500kb，支持.jpg、.gif、.png等格式</div>
          </el-form-item>
          <el-form-item label="店铺公告:">
            <el-input v-model="shop.notice" style="width: 400px;" />
          </el-form-item>
          <el-form-item label="店铺介绍:">
            <el-input v-model="shop.detail" :rows="2" type="textarea" style="width: 400px;" />
          </el-form-item>
          <el-form-item label="营业执照:" prop="license">
            <el-upload
              :show-file-list="false"
              :on-success="mainImgUpload1"
              :before-upload="beforeUserImgUpload1"
              :action="userHeadUploadApi"
              class="avatar-uploader">
              <img v-if="shop.license" :src="shop.license" style="width: 100px; height: 100px" class="avatar">
              <i v-else class="el-icon-plus avatar-uploader-icon" />
            </el-upload>
            <div style="font-size: 10px;color:#606266">建议尺寸：200×200px ，大小不能超过3M，支持.jpg、.gif、.png等格式</div>
          </el-form-item>
          <el-form-item label="维权客服电话:">
            <el-input v-model="shop.complaint_call" style="width: 400px;" />
            <span style="font-size:10px;color:#606266">手机号将用于接收买家维权咨询、维权通知提醒</span>
          </el-form-item>
          <el-form-item label="">
            <el-input v-model="shop.area_code" style="width: 170px;" /> -- <el-input v-model="shop.landline" style="width: 170px;" />
            <span style="font-size: 10px;color:#606266">优先展示座机号码</span>
          </el-form-item>
        </el-form>
        <!--表单组件-->
        <addForm ref="addForm" />
        <editForm ref="editForm" />
        <!--地址管理-->
        <!--表格渲染-->
        <div style="display:flex;justify-content:space-between">
          <div />
          <el-button v-if="statusId === 2" type="primary" align="center" size="small" style="margin-bottom:15px" @click="add">添加地址</el-button>
        </div>
        <el-table v-loading="loading1" v-if="statusId === 2" ref="table" :data="address" size="small" style="width: 100%;">
          <el-table-column label="序号" width="100">
            <template slot-scope="scope">
              <span>{{ scope.$index + 1 }} </span>
            </template>
          </el-table-column>
          <el-table-column prop="contacts" label="联系人" align="center" width="100"/>
          <el-table-column prop="tel" label="联系电话" align="center"/>
          <el-table-column prop="landline_telephone" label="座机" align="center" />
          <el-table-column label="地址" align="center" width="200" show-overflow-tooltip>
            <template slot-scope="scope">
              <span>{{ scope.row.province }}{{ scope.row.city }}{{ scope.row.street }}</span>
            </template>
          </el-table-column>
          <el-table-column prop="card_used" label="地址类型" align="center">
            <template slot-scope="scope">
              <span v-if="scope.row.type === 1">退货地址</span>
              <span v-else>收货地址</span>
            </template>
          </el-table-column>
          <el-table-column prop="card_used" label="操作" align="center" >
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="primary"
                icon="el-icon-edit"
                @click="edit(scope.row)" />
              <el-popover
                :ref="scope.row.number"
                placement="top"
                width="180">
                <p>确定删除本条数据吗？</p>
                <div style="text-align: right; margin: 0">
                  <el-button
                    size="mini"
                    type="text"
                    @click="$refs[scope.row.number].doClose()">取消</el-button>
                  <el-button
                    :loading="delLoading"
                    type="primary"
                    size="mini"
                    @click="subDelete(scope.row.number)">确定</el-button>
                </div>
                <el-button
                  slot="reference"
                  type="danger"
                  icon="el-icon-delete"
                  size="mini" />
              </el-popover>
            </template>
          </el-table-column>
        </el-table>
        <!-- 运费模版 -->
        <div v-if="!isAddFreightShow && !isEditFreightShow && !isCopyFreightShow">
          <div style="display:flex;justify-content:space-between">
            <div />
            <el-button v-if="statusId === 3" type="primary" align="center" size="small" style="margin-bottom:15px" @click="addFreight">新建运费模板</el-button>
          </div>
          <el-table
            v-if="statusId === 3"
            :data="freightList"
            size="small"
            style="width: 100%">
            <el-table-column type="expand">
              <template slot-scope="props">
                <el-table :data="props.row.area" size="small" style="width: 100%">
                  <el-table-column prop="area" label="可配送区域"/>
                  <el-table-column prop="freight" label="运费"/>
                </el-table>
              </template>
            </el-table-column>
            <el-table-column label="模板名称" prop="template_name"/>
            <el-table-column
              fixed="right"
              width="370"
              label="操作">
              <template slot-scope="scope">
                <el-button type="text" size="small" style="color:#909399">最后编辑时间：{{ parseTime(Number(scope.row.editor_time)) }}</el-button>
                <el-button type="text" size="small" @click="copyFreight(scope.row)">复制模版</el-button>
                <el-button type="text" size="small" @click="editFreight(scope.row)">编辑</el-button>
                <el-button type="text" size="small" @click="doDelete(scope.row.template_id)">删除</el-button>
              </template>
            </el-table-column>
          </el-table>
        </div>
        <addFreight v-if="isAddFreightShow && statusId === 3" ref="addFreight" />
        <editFreight v-if="isEditFreightShow && statusId === 3" ref="editFreight" :data="freightInfo" />
        <copyFreight v-if="isCopyFreightShow && statusId === 3" ref="copyFreight" :data="freightInfo" />
      </div>
      <!--通用设置-->
      <el-form v-if="statusId === 4" :model="shop" label-width="120px">
        <!--        <el-form-item label="宝贝公告:" >-->
        <!--          <el-upload-->
        <!--            :show-file-list="false"-->
        <!--            :on-success="mainImgUpload2"-->
        <!--            :before-upload="beforeUserImgUpload"-->
        <!--            :action="userHeadUploadApi"-->
        <!--            class="avatar-uploader">-->
        <!--            <img v-if="shop.notice_url" :src="shop.notice_url" style="width: 100px; height: 100px" class="avatar">-->
        <!--            <i v-else class="el-icon-plus avatar-uploader-icon" />-->
        <!--          </el-upload>-->
        <!--          <el-row style="font-size: 10px;color:#606266">建议尺寸：200×200px ，大小不能超过500kb，支持.jpg、.gif、.png等格式</el-row>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="宝贝须知:" >-->
        <!--          <el-upload-->
        <!--            :show-file-list="false"-->
        <!--            :on-success="mainImgUpload3"-->
        <!--            :before-upload="beforeUserImgUpload"-->
        <!--            :action="userHeadUploadApi"-->
        <!--            class="avatar-uploader">-->
        <!--            <img v-if="shop.know_url" :src="shop.know_url" style="width: 100px; height: 100px" class="avatar">-->
        <!--            <i v-else class="el-icon-plus avatar-uploader-icon" />-->
        <!--          </el-upload>-->
        <!--          <el-row style="font-size: 10px;color:#606266">建议尺寸：200×200px ，大小不能超过500kb，支持.jpg、.gif、.png等格式</el-row>-->
        <!--        </el-form-item>-->
        <el-form-item label="分享海报背景图:" >
          <el-upload
            :show-file-list="false"
            :on-success="mainImgUpload4"
            :before-upload="beforeUserImgUpload1"
            :action="userHeadUploadApi"
            class="avatar-uploader">
            <img v-if="shop.share_poster_img" :src="shop.share_poster_img" style="width: 100px; height: 100px" class="avatar">
            <i v-else class="el-icon-plus avatar-uploader-icon" />
          </el-upload>
          <p style="font-size: 10px;color:#606266">建议尺寸：750×955像素 ，小于3Mb，支持.jpg、.gif、.png等格式</p>
        </el-form-item>
        <!--        <el-form-item label="会员资产展示图:" >-->
        <!--          <el-upload-->
        <!--            :show-file-list="false"-->
        <!--            :on-success="mainImgUpload5"-->
        <!--            :before-upload="beforeUserImgUpload2"-->
        <!--            :action="userHeadUploadApi"-->
        <!--            class="avatar-uploader">-->
        <!--            <img v-if="shop.vip_img" :src="shop.vip_img" style="width: 100px; height: 100px" class="avatar">-->
        <!--            <i v-else class="el-icon-plus avatar-uploader-icon" />-->
        <!--          </el-upload>-->
        <!--          <p style="font-size: 10px;color:#606266">建议尺寸：比例1:1 ，小于1MB，支持.jpg、.gif、.png等格式</p>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="销量:" >-->
        <!--          <template>-->
        <!--            <el-radio v-model="shop.is_sales" label="1">显示</el-radio>-->
        <!--            <el-radio v-model="shop.is_sales" label="0">不显示</el-radio>-->
        <!--          </template>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="留言:" >-->
        <!--          <template>-->
        <!--            <el-radio v-model="shop.is_message" label="1">开启</el-radio>-->
        <!--            <el-radio v-model="shop.is_message" label="0">关闭</el-radio>-->
        <!--          </template>-->
        <!--        </el-form-item>-->
        <!--        <el-form-item label="分享方式:" >-->
        <!--          <template>-->
        <!--            <el-radio v-model="shop.share_way" label="1">小程序</el-radio>-->
        <!--            <el-radio v-model="shop.share_way" label="0">H5</el-radio>-->
        <!--          </template>-->
        <!--        </el-form-item>-->
      </el-form>
      <!--交易设置-->
      <div v-if="statusId === 5">
        <el-form :model="shop" :label-position="labelPosition.left" label-width="190px">
          <div>
            <span style="font-weight: bold">交易设置</span>
            <el-divider />
          </div>
          <el-form-item label="库存计数:">
            <template>
              <el-radio v-model="shop.inventory_count" label="0">拍下减库存</el-radio>
              <el-radio v-model="shop.inventory_count" label="1">支付减库存</el-radio>
            </template>
          </el-form-item>
          <el-form-item label="待付款订单取消时间:">
            拍下未付款订单 <el-input v-model="shop.payment_time" size="small" style="width: 170px;" /> 分钟内未付款，自动取消订单
          </el-form-item>
          <div style="margin-top: 50px">
            <span style="font-weight: bold">礼物领取规则设置</span>
            <el-divider />
          </div>
          <el-form-item label="是否启用自定义领取:">
            <el-switch
              v-model="is_open_gift_receive_time"
              class="switchStyle"
              active-text="是"
              inactive-text="否"
              @change="openGiftReceiveTimeChange"
            />
          </el-form-item>
          <el-form-item label="当前时间礼物可领取的日期:">
            <el-date-picker
              v-model="timestampList"
              :disabled="!is_open_gift_receive_time"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
              value-format="timestamp"
              @change="receiveGiftDateChange"
            />
          </el-form-item>
        </el-form>
      </div>
      <!--分佣设置-->
      <div v-if="statusId === 6">
        <el-card class="box-card">
          <div slot="header" class="clearfix">
            <span>佣金设置</span>
          </div>
          <el-form :model="shop" :label-position="labelPosition.left" class="form-container" label-width="120px" >
            <el-form-item label="推广员推广收益:">
              团长佣金总额的 <el-input v-model="shop.commission_promoter" size="small" style="width: 80px;" /> %作为推广员推广返利
            </el-form-item>
            <el-form-item label="团长推广收益:">
              省长佣金总额的 <el-input v-model="shop.commission_team" size="small" style="width: 80px;" /> %作为团长推广返利
            </el-form-item>
            <el-form-item label="最低推广收益：">
              产品佣金总额的 <el-input v-model="shop.commission_mini" size="small" style="width: 80px;" /> %作为团长、推广员的最低收益
              <span style="color: red;">注意：设置低于最低收益，则不能保存</span>
            </el-form-item>
          </el-form>
        </el-card>
        <el-card class="box-card" style="margin-top:10px">
          <div slot="header" class="clearfix">
            <span>提现设置</span>
          </div>
          <el-form :model="shop" :label-position="labelPosition.left" class="form-container" label-width="100px" >
            <el-form-item label="提现金额满:">
              <el-input v-model="shop.receipt_limit" size="small" style="width: 100px;" /> 元，可以提现
            </el-form-item>
          </el-form>
        </el-card>
      </div>
      <div class="fixed-bottom">
        <div/>
        <el-button v-if="statusId !== 2 && statusId !== 3" type="primary" size="small" @click="updata">保存</el-button>
      </div>
    </div>
  </div>
</template>

<script>
import addForm from './add'
import editForm from './edit'
import initData from '@/mixins/initData'
import { parseDate, parseTime } from '@/utils/index'
import { updateBaseMall, delTemplateById, deleteAddressById, mallList, freightList } from '@/api/mall/shopconfigRequest'
import { mapGetters } from 'vuex'
import addFreight from './addFreight'
import editFreight from './editFreight'
import copyFreight from './copyFreight'
export default {
  components: { addForm, editForm, addFreight, editFreight, copyFreight },
  mixins: [initData],
  data() {
    return {
      shelf: '',
      shop: {},
      rules: {
        shop_name: []
      },
      activeName: '6',
      statusId: 6,
      address: [],
      freightList: [], // 运费模版列表
      isAddFreightShow: false, // 是否显示新增运费列表
      isEditFreightShow: false, // 是否显示新增运费列表
      isCopyFreightShow: false, // 是否显示复制运费列表
      freightInfo: {}, // 运费模版信息
      labelPosition: {
        right: 'right',
        left: 'left'
      },
      data: {
        number: ''
      },
      data1: {
        template_id: ''
      },
      province_id: '',
      loading1: false,
      delLoading: false, expand: true,
      mapJson: '../../static/json/map.json',
      province: '',
      sheng: '',
      shi: '',
      shi1: [],
      qu: '',
      qu1: [],
      city: '',
      is_open_gift_receive_time: false,
      timestampList: []
    }
  },
  computed: {
    ...mapGetters([
      'userHeadUploadApi'
    ])
  },
  watch: {
    activeName(data) {
      // 监听到标签栏绑定数据发生了变化，重新加载表格数据，
      this.statusId = parseInt(data)
      this.$nextTick(() => {
        this.init()
      })
    }
  },
  created() {
    const status_id = this.$route.query.status_id
    if (status_id && status_id.length > 0) {
      this.activeName = status_id
    }
    this.$nextTick(() => {
      this.init()
    })
    // 获取地址管理列表
    this.getMallList()
    // 获取运费模板列表
    this.getFreightList()
    // 获取地址信息
    this.getCityData()
  },
  methods: {
    parseDate,
    parseTime,
    beforeInit() {
    },
    // 加载china地点数据，三级
    getCityData: function() {
      var that = this
      this.$axios.get(this.mapJson).then(function(response) {
        if (response.status === 200) {
          var data = response.data
          that.province = []
          that.city = []
          that.block = []
          // 省市区数据分类
          for (var item in data) {
            // 省
            if (item.match(/0000$/)) {
              that.province.push({ id: item, value: data[item], children: [] })
              // 市
            } else if (item.match(/00$/)) {
              that.city.push({ id: item, value: data[item], children: [] })
              // 区
            } else {
              that.block.push({ id: item, value: data[item] })
            }
          }
          // 分类市级
          for (var index in that.province) {
            for (var index1 in that.city) {
              if (that.province[index].id.slice(0, 2) === that.city[index1].id.slice(0, 2)) {
                that.province[index].children.push(that.city[index1])
              }
            }
          }
          // 分类区级
          for (var item1 in that.city) {
            for (var item2 in that.block) {
              if (that.block[item2].id.slice(0, 4) === that.city[item1].id.slice(0, 4)) {
                that.city[item1].children.push(that.block[item2])
              }
            }
          }
        }
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '获取地址列表失败'
        })
      })
    },
    // 获取地址管理列表
    getMallList() {
      this.loading = true
      this.loading1 = true
      var regPos = /^[0-9]+.?[0-9]*$/
      mallList().then(res => {
        if (res.result) {
          // 获取店铺信息
          this.shop = res.shop
          if (this.shop.open_gift_receive_time) {
            this.is_open_gift_receive_time = (this.shop.open_gift_receive_time === 1)
          }
          if (this.shop.gift_receive_time_start && this.shop.gift_receive_time_end) {
            this.timestampList[0] = this.shop.gift_receive_time_start
            this.timestampList[1] = this.shop.gift_receive_time_end
          }
          // 拼接字符串用于单选按钮显示
          this.shop.share_way = res.shop.share_way + ''
          this.shop.is_message = res.shop.is_message + ''
          this.shop.is_sales = res.shop.is_sales + ''
          this.shop.inventory_count = res.shop.inventory_count + ''
          // 获取地址信息
          if (res.shop.address_setting) {
            for (let i = 0; i < res.shop.address_setting.length; i++) {
              if (res.shop.address_setting[i].is_remove === 1) {
                if (regPos.test(res.shop.address_setting[i].province)) {
                  this.province.map(item => {
                    // 根据省的id获取对应省的值
                    if (item.id === res.shop.address_setting[i].province) {
                      res.shop.address_setting[i].province = item.value
                    }
                  })
                }
                // 根据市的id获取对应市的值
                if (regPos.test(res.shop.address_setting[i].city)) {
                  this.city.map(item => {
                    if (item.id === res.shop.address_setting[i].city) {
                      res.shop.address_setting[i].city = item.value
                    }
                  })
                }
                this.address.push(res.shop.address_setting[i])
              }
            }
          }
        }
        this.loading = false
        this.loading1 = false
      })
    },
    // 获取运费列表
    getFreightList() {
      freightList().then(res => {
        this.freightList = res.freight
      })
    },
    // 新建运费模版
    addFreight() {
      this.isAddFreightShow = true
    },
    // 编辑运费模版
    editFreight(data) {
      console.log('data', data)
      this.isEditFreightShow = true
      this.freightInfo = data
    },
    // 复制运费模版
    copyFreight(data) {
      console.log('data', data)
      this.isCopyFreightShow = true
      this.freightInfo = data
    },
    add() {
      // 添加弹框
      this.isAdd = false
      const _this = this.$refs.addForm
      _this.sheng = ''
      _this.shi = ''
      _this.province = this.province
      _this.shi1 = this.shi1
      _this.dialog = true
    },
    edit(data) {
      // 添加弹框
      this.isAdd = false
      const _this = this.$refs.editForm
      // 编辑时将省的值转换成id用于查询相对应的市
      this.province.map(item => {
        if (item.value === data.province) {
          this.province_id = item.id
        }
      })
      _this.choseProvince(this.province_id)
      _this.dialog1 = true
      _this.form = {
        number: data.number,
        contacts: data.contacts,
        landline_telephone: data.landline_telephone,
        province: data.province,
        city: data.city,
        street: data.street,
        type: data.type + '',
        tel: data.tel
      }
      _this.province = this.province
      _this.shi1 = this.shi1
    },
    subDelete(number) {
      this.data.number = number
      this.delLoading = true
      deleteAddressById(this.data).then(res => {
        if (res) {
          this.delLoading = false
          this.$notify({
            title: '删除成功',
            type: 'success',
            duration: 2500
          })
          this.address = []
          this.getMallList()
        } else {
          this.delLoading = false
          this.$notify({
            title: '删除失败',
            type: 'error',
            duration: 2500
          })
          this.loading1 = false
        }
      })
    },
    logoImgSuccess(res, file) {
      // 用于回显图片内容，不用oss返回的地址主要是节省流量
      this.shop.icon = URL.createObjectURL(file.raw)
      // 后台返回的oss地址，存储对象里，用于保存信息时使用
      this.shop.icon = res
    },
    beforeUserImgUpload(file) {
      const isJPG = file.type === 'image/jpeg' || file.type === 'image/gif' || file.type === 'image/png'
      // const isLt2M = file.size / 1024 / 1024 < 2
      const isLt2M = file.size / 1024 <= 500
      if (!isJPG) {
        this.$message.error('上传头像图片只支持.jpg、.gif、.png等格式!')
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 500kb!')
      }
      return isJPG && isLt2M
    },
    beforeUserImgUpload1(file) {
      const isJPG = file.type === 'image/jpeg' || file.type === 'image/gif' || file.type === 'image/png'
      const isLt2M = file.size / 1024 / 1024 < 3
      if (!isJPG) {
        this.$message.error('上传头像图片只支持.jpg、.gif、.png等格式!')
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 3M!')
      }
      return isJPG && isLt2M
    },
    beforeUserImgUpload2(file) {
      const isJPG = file.type === 'image/jpeg' || file.type === 'image/gif' || file.type === 'image/png'
      const isLt2M = file.size / 1024 / 1024 < 1
      if (!isJPG) {
        this.$message.error('上传头像图片只支持.jpg、.gif、.png等格式!')
      }
      if (!isLt2M) {
        this.$message.error('上传头像图片大小不能超过 1M!')
      }
      return isJPG && isLt2M
    },
    mainImgUpload1(res, file) {
      // 用于回显图片内容，不用oss返回的地址主要是节省流量
      this.shop.license = URL.createObjectURL(file.raw)
      this.shop.license = res
    },
    mainImgUpload2(res, file) {
      // 用于回显图片内容，不用oss返回的地址主要是节省流量
      this.shop.notice_url = URL.createObjectURL(file.raw)
      this.shop.notice_url = res
    },
    mainImgUpload3(res, file) {
      // 用于回显图片内容，不用oss返回的地址主要是节省流量
      this.shop.know_url = URL.createObjectURL(file.raw)
      this.shop.know_url = res
    },
    mainImgUpload4(res, file) {
      // 用于回显图片内容，不用oss返回的地址主要是节省流量
      this.shop.share_poster_img = URL.createObjectURL(file.raw)
      this.shop.share_poster_img = res
    },
    mainImgUpload5(res, file) {
      // 用于回显图片内容，不用oss返回的地址主要是节省流量
      this.shop.vip_img = URL.createObjectURL(file.raw)
      this.shop.vip_img = res
    },
    doDelete(id) {
      this.$confirm('是否删除此模板?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        this.data1.template_id = id
        delTemplateById(this.data1).then(res => {
          if (res) {
            this.$notify({
              title: '删除成功',
              type: 'success',
              duration: 2500
            })
            this.getFreightList()
          } else {
            this.$notify({
              title: '删除失败',
              type: 'error',
              duration: 2500
            })
          }
        })
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消删除'
        })
      })
    },
    updata() {
      const reg1 = /^[0-9]+([.]{1}[0-9]{1,2})?$/
      if (this.shop.mall_name === '') {
        this.$notify({
          title: '店铺名不能为空',
          type: 'warning',
          duration: 2500
        })
        return
      }
      if (!reg1.test(this.shop.receipt_limit)) {
        this.$notify({
          title: '提现金额只能输入正整数或最多俩位小数',
          type: 'warning',
          duration: 2500
        })
        return
      }
      if (this.shop.open_gift_receive_time && this.shop.open_gift_receive_time === 1) {
        if (!this.shop.gift_receive_time_start || !this.shop.gift_receive_time_end) {
          this.$notify({
            title: '自定义礼物领取时间不能为空',
            type: 'warning',
            duration: 2500
          })
          return
        }
      }
      if (!reg1.test(this.shop.commission_promoter) || !reg1.test(this.shop.commission_mini) || !reg1.test(this.shop.commission_team)) {
        this.$notify({
          title: '设置只能输入正整数',
          type: 'warning',
          duration: 2500
        })
        return
      }
      if (this.shop.commission_promoter < this.shop.commission_mini || this.shop.commission_team < this.shop.commission_mini) {
        this.$notify({
          title: '设置不能低于最低收益',
          type: 'warning',
          duration: 3000
        })
        return
      }
      updateBaseMall(this.shop).then(res => {
        if (res) {
          this.$notify({
            title: '保存成功',
            type: 'success',
            duration: 2500
          })
        } else {
          this.$notify({
            title: '保存失败',
            type: 'error',
            duration: 2500
          })
        }
      })
    },
    receiveGiftDateChange(val) {
      if (val) {
        this.shop.gift_receive_time_start = val[0]
        this.shop.gift_receive_time_end = val[1]
      } else {
        this.shop.gift_receive_time_start = ''
        this.shop.gift_receive_time_end = ''
      }
    },
    openGiftReceiveTimeChange(val) {
      this.shop.open_gift_receive_time = !val ? 0 : 1
    }
  }
}
</script>

<style lang="scss">
.freight-template {
  width: 100%;
  margin-top: 20px;
  .freight-template-list {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid #E4E7ED;
    padding: 15px 10px;
    background-color: #F2F6FC;
    font-size: 12px;
    color: #909399;
    .freight-template-list-title {
      color: #606266;
    }
    .blue {
      color: #1890ff;
    }
    .edit-time {
      margin-right: 10px;
    }
  }
}
.el-table__body-wrapper {
    min-height: 0!important;
}
.fixed-bottom {
  position: absolute;
  bottom: 0;
  z-index: 10099;
  background: hsla(0,0%,100%,.95);
  padding: 10px;
  border-top: none;
  width: calc(100% - 20px);
  box-shadow: 0 -3px 5px #eee;
  text-align: center;
  background: #fff;
  left: 50%;
  transform: translateX(-50%);
}
.switchStyle .el-switch__label {
   position: absolute;
   display: none;
   color: #ffffff;
 }
/*打开时文字位置设置*/
.switchStyle .el-switch__label--right {
  z-index: 1;
  right: -8px;
}
/*关闭时文字位置设置*/
.switchStyle .el-switch__label--left {
  z-index: 1;
  left: 28px;
}
/*显示文字*/
.switchStyle .el-switch__label.is-active {
  display: block;
}
.switchStyle.el-switch .el-switch__core,
.switchStyle.el-switch .el-switch__label {
  width: 50px !important;
}
</style>
